package ex4.gui;

import java.awt.Frame;

import javax.swing.JFrame;

import ex4.logic.Configuration;
import ex4.logic.Score;
import ex4.logic.Snake;



public class EnterYourNameScreen extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private javax.swing.JButton _okButton;
	private javax.swing.JTextField _name;
	private int _score;

	public EnterYourNameScreen(int score){

		_score=score;
		_okButton = new javax.swing.JButton();
		_name = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		_okButton.setText("O.k");
		_okButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				okButtonPressed(evt);
			}
		});

		_name.setText("Enter you'r name");


		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(layout.createSequentialGroup()
										.addGap(118, 118, 118)
										.addComponent(_name, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGroup(layout.createSequentialGroup()
												.addGap(168, 168, 168)
												.addComponent(_okButton)))
												.addContainerGap(133, Short.MAX_VALUE))
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addGap(110, 110, 110)
						.addComponent(_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(29, 29, 29)
						.addComponent(_okButton)
						.addContainerGap(118, Short.MAX_VALUE))
		);

	}

	private void okButtonPressed(java.awt.event.ActionEvent evt) {
		Score tScore=new Score(_score,_name.getText());
		Configuration._scores.add(tScore);
		Frame frame=new HighScoreScreen();
		frame.setSize(800,600);
		frame.setVisible(true);
		this.dispose();
	}



}
